package com.yunhe.authority.repository.app;

import com.yunhe.authority.domain.app.AppPushInfo;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhengbo
 * @date 2021/11/10 17:43
 * App推送信息
 */

@Repository
public interface AppPushInfoRepository extends Neo4jRepository<AppPushInfo, Long> {

    @Query("match(u:User),(a:AppPushInfo) " +
            "where id(u)={userId} and id(a)={id}" +
            "create (a)-[r:BELONG_APP_USER]->(u)")
    void bindUser(@Param("userId")Long userId,
                  @Param("id")Long id);

    void deleteByUserIdAndDeviceIdAndRegistrationId(@Param("userId")Long userId,
                                                    @Param("registrationId")String registrationId,
                                                    @Param("deviceId")String deviceId);

    AppPushInfo findByUserIdAndDeviceId(@Param("userId") Long userId, @Param("deviceId")String deviceId);

    @Query("match (a:AppPushInfo)-[r:BELONG_APP_USER]->(u:User) where id(u)={userId} return a")
    List<AppPushInfo> findByUserId(@Param("userId")Long userId);

    @Query("match (a:AppPushInfo)-[r:BELONG_APP_USER]->(u:User) where id(u) in {userIds} return a")
    List<AppPushInfo> findByUserIdList(@Param("userIds")List<Long> userIds);

    @Query("match (a:AppPushInfo)-[r:BELONG_APP_USER]->(u:User)-[:HAS_STATION]->(s:Station) where id(s)={stationId} return a")
    List<AppPushInfo> findByStationId(@Param("stationId")Long stationId);



}
